#!/bin/sh

XUSER=root

. /etc/init.d/functions

# Note, this is allowed to `exit` out if the server is considered disabled
[ -f /etc/default/xserver-xfce ] && . /etc/default/xserver-xfce

for x in $(cat /proc/cmdline); do
	case $x in
		x11=false)
			echo "X Server disabled" 
			exit 0;
			;;
	esac
done

case "$1" in
	start)
		# We don't want this script to block the rest of the boot process
		if [ "$2" != "background" ]; then
			$0 $1 background &
		else
			echo "Starting xfce4."
			exec su -c startxfce4 - $XUSER >/var/log/Xsession.log 2>&1
		fi 
		;;

	stop)
		echo "Stopping XServer"
		killproc xinit
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;

	*)
		echo "usage: $0 { start | stop | restart }"
		;;
esac

exit 0
